import 'package:center_beijing/common/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class SearchWidget extends StatefulWidget {

  final String placeholder;
  final bool disabled;
  final TextEditingController textInput;
  final Function textSubmit;
  SearchWidget(
      {this.placeholder='请输入',this.disabled=false,this.textInput,this.textSubmit});

  @override
  _SearchWidgetState createState() => _SearchWidgetState();
}

class _SearchWidgetState extends State<SearchWidget> {


  @override
  Widget build(BuildContext context) {
    return Container(
      child: Container(
        padding: EdgeInsets.fromLTRB(Styles.spacing16, 0, Styles.spacing16, 0),
          decoration:BoxDecoration(
            //背景
            color: Styles.LightSearch,
            //设置四周圆角 角度
            borderRadius: BorderRadius.all(Radius.circular(18.0)),
          ),
        child:Row(
          children: [
            Container(
              margin: EdgeInsets.fromLTRB(0, 0, Styles.spacing8, 0),
              alignment: Alignment.center,
              child: Image(
                image: AssetImage('assets/images/icon_search_glass_normal.png'),
                width: 20,
                height: 20,
                fit: BoxFit.contain,
              ),
            ),
            Expanded(child: Container(
              child: TextField(
                controller: widget.textInput,
                obscureText: false,
                textAlign: TextAlign.left,
                style: TextStyle(fontSize: Styles.NormalFont),
                textInputAction:TextInputAction.search,
                decoration: InputDecoration(
                  isCollapsed: true,
                  contentPadding:
                  EdgeInsets.symmetric(vertical: 8,),
                  hintStyle: TextStyle(
                      fontSize: Styles.NormalFont, color: Styles.TitleColor),
                  hintText: widget.placeholder,
                  border: InputBorder.none,
                ),
                enabled: !widget.disabled,
                onSubmitted: widget.textSubmit,
              ),
            ))
          ],
        ) ,
      ) ,
    );
  }
}
